package com.dyb.recuitment.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dyb.recuitment.entity.Setting;
import com.dyb.recuitment.entity.UserLog;
import com.dyb.recuitment.mapper.UserLogMapper;
import com.dyb.recuitment.service.IUserLogService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 用户日志表 服务实现类
 * </p>
 *
 * @author 邓宇斌
 * @since 2022-02-21
 */
@Service
public class UserLogServiceImpl extends ServiceImpl<UserLogMapper, UserLog> implements IUserLogService {

    @Autowired
    private UserLogMapper userLogMapper;

    DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

    @Override
    public int add(UserLog userLog) {
        LocalDateTime localDateTime = LocalDateTime.parse(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()), df);
        userLog.setCreateTime(localDateTime).setUpdateTime(localDateTime);
        return userLogMapper.insert(userLog);
    }

    @Override
    public List<UserLog> selectByUserLog(UserLog userLog) {
        userLog.setStatus(1);
        QueryWrapper<UserLog> queryWrapper = new QueryWrapper<>(userLog);
        return userLog.selectList(queryWrapper);
    }

    @Override
    public List<UserLog> selectAllUserLog() {
        return userLogMapper.selectList(new QueryWrapper<>());
    }

}
